package com.szd.qiongyou20.home.search.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.szd.qiongyou20.R;
import com.szd.qiongyou20.home.search.bean.JnBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by SZD on 2016/12/26.
 */

public class Jn_ListView_Adapter extends BaseAdapter {

    private Context mContext;
    private List<JnBean.DataBean.EntryBean> mList;

    public Jn_ListView_Adapter(Context context, List<JnBean.DataBean.EntryBean> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_search_jn, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        // 获取数据
        String name = mList.get(position).getName();
        String country_name = mList.get(position).getCountry_name();
        String continent_name = mList.get(position).getContinent_name();
        String updatetime = mList.get(position).getUpdatetime();

        // 将数据添加到View中
        holder.mTextViewSearchJnPlace.setTag(name);
        holder.mTextViewSearchJnConutry.setText(continent_name+"/"+country_name);
        holder.mTextViewSearchJnTime.setText(updatetime+ "更新");

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.imageView_search_jn)
        ImageView mImageViewSearchJn;
        @Bind(R.id.textView_search_jn_place)
        TextView mTextViewSearchJnPlace;
        @Bind(R.id.textView_search_jn_conutry)
        TextView mTextViewSearchJnConutry;
        @Bind(R.id.textView_search_jn_time)
        TextView mTextViewSearchJnTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
